<?php
require_once ("db.inc");
require_once ("math.inc");

$query = "
SELECT sm.`id` as idd, `link`, count(sm.`id`) as dcount FROM `simple` sm
inner join `statistic` st
on st.linkid = sm.id
group by `link`,sm.`id`
order by dcount desc";

if ( $result = getmysqli_query ($query))
{
    //var_dump($result);
    $linkcount = "SELECT count(*) as cnt FROM `simple`";
    $linkcount = getmysqli_query ($linkcount);
    $linkcount = $linkcount[0]['cnt'];

    $pos = "SELECT count(*) as cnt FROM `statistic`";
    $pos = getmysqli_query ($pos);
    $pos = $pos[0]['cnt'];
    echo "
<!DOCTYPE html>
<html lang='ru'>
<head>
    <meta charset='utf-8' />
    <meta http-equiv='refresh' content='10'>    
    <style type='text/css'>
        table, td, th
        {
        border:1px solid green;color: green;
        }
        th
        {
        background-color:green;
        color:white;
        }
        a:link {color: green;text-decortaion: none;}    /* unvisited link */
        a:visited {color: green;text-decortaion: none;} /* visited link */
        a:hover {color: green;text-decortaion: none;}   /* mouse over link */
        a:active {color: green;text-decortaion: none;}  /* selected link */    
    </style>
</head>
<body>";
    echo "<p><h2>Статистика переходов (".count($result)." активных из сокращенных ".$linkcount." ссылок, при ".$pos." посещениях )</h2></p>
<a href='http://путя.рф/зУ'>Яндекс</a>
<hr>";
    echo "<table rules=all style='border: 1px; background-color: #eaeaea; margin: 0 auto' cellpadding=1>";
    echo "<tr><th>Ссылка</th><th>Переходов</th></tr>";
    for ($i=0;$i<count($result);$i++){
        echo "<tr>";
        $rfurl = get76from10($result[$i]['idd']);
        echo "<td><a href='/".$rfurl."'>".substr($result[$i]['link'],0,100)."</a></td>";
        echo "<td>".$result[$i]['dcount']."</td>";
        echo "</tr>";
    }
    echo "</table>
</body>";
}
?>
